package candy;

import java.io.Serializable;

public class ChocoCandy extends MilkCandy implements Serializable{
	protected ChocoType chocotype;

	public ChocoCandy(int id, String name, double albumens, double fats,
			double carbohydrates, double weight, double price,
			double rateOfMilk, ChocoType chocotype) {
		super(id, name, albumens, fats, carbohydrates, weight, price,
				rateOfMilk);
		this.chocotype = chocotype;
	}

	@Override
	protected double calculateCalorificValue() {
		return 5.35 * (this.getAlbumens() + this.getCarbohydrates() + this
				.getFats());
	}

	public ChocoType getChocotype() {
		return chocotype;
	}

	public void setChocotype(ChocoType chocotype) {
		this.chocotype = chocotype;
	}

	@Override
	public String toString() {
		String str = "";
		str = "ChocoCandy #" + this.id + "  " + this.name + "\n"
				+ "albumens = " + this.albumens + " carbohydrates = "
				+ this.carbohydrates + "\n" + "fats = " + this.fats
				+ " rate of milk = " + this.rateOfMilk + "\n"
				+ " calorific value = " + this.calculateCalorificValue() + "\n"
				+ "weight = " + this.weight + " price = " + this.price + "\n"
				+ "chocotype = " + this.chocotype + "\n" + "-----------------";
		return str;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result
				+ ((chocotype == null) ? 0 : chocotype.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (!super.equals(obj)) {
			return false;
		}
		if (!(obj instanceof ChocoCandy)) {
			return false;
		}
		ChocoCandy other = (ChocoCandy) obj;
		if (chocotype != other.chocotype) {
			return false;
		}
		return true;
	}

}
